/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gerenciar;

import entidades.Servicos;
import java.util.List;
import javax.swing.JOptionPane;

import org.hibernate.classic.Session;

/**
 *
 * @author Deyves
 */
public class GerenciarServico {

    public static boolean gravar(Servicos serv) {
        try {
            Session session = DaoHibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            session.saveOrUpdate(serv);
            session.getTransaction().commit();
            session.close();
            return true;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao inserir no Banco de Dados!");

            return false;
        }
    }
    
        
    public static List<Servicos> trazerServicos(){
        Session session= DaoHibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        List<Servicos> lista=session.createQuery("FROM Servicos").list();
        session.getTransaction().commit();
        session.close();
        return lista;
    }
    
    public static boolean excluir(Servicos serv) {
        try {
            Session session=DaoHibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            session.delete(serv);
            session.getTransaction().commit();
            session.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
